﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.ComponentModel;
using System.Drawing;
using System.IO;

namespace Twillo.Core.Controls
{
    public class UserControlBase : UserControl
    {
        [Category("Connection")]
        public WebProxy Proxy
        {
            get
            {
                if (DesignMode) { return null; }
                return Twillo.Core.Web.Proxy.WebProxy;
            }
        }

        protected Image EmptyImage()
        {
            Bitmap bmp = new Bitmap(1, 1);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.Clear(this.BackColor);
            }

            return bmp;
        }
        protected Image LoadImage(string uri)
        {
            HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
            request.Proxy = this.Proxy;
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream stream = response.GetResponseStream();
            Image img = Image.FromStream(stream);
            stream.Flush();
            response.Close();
            return img;
        }
    }
}
